<script>
    function getIndexOf(array, key) {
        // 1.查找数组的长度
        let low = 0;
        let high = array.length-1;
        // 索引值0<=最大的索引
        while(low<=high){
            // 取到中间的索引  1- 0  2- 1  3- 1  4-2
            let mid = Math.floor((low+high)/2);
            if(key === array[mid]){
                return mid;
            }else if(key>array[mid]){
                low = mid + 1;
            }else{
                high = mid -1;
            }
        }
    }
</script>